package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.game.ActorRole;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPalette;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

/**
 * 队伍界面
 * 
 * @author xjp
 */
public class UITeamWindow extends UIAbstractWindow
{
	private final int TEAM_SELF = 0;
	private final int TEAM_NEAR = 1;

	public UITeamWindow(int id)
	{
		super(id);
		m_state = TEAM_SELF;
		initImage(); // 初始化图片资源

		setBounds(UITools.X_BG, UITools.Y_BG, UITools.W_BG, UITools.H_BG);
	}

	
//	private final String m_Sure = "确定";
//	private final String m_Return = "返回";

	public void registerTouch() {
		super.registerTouch();
		clearAllRects();
		registerNormalSoft();
		initTouchRect(topRect);
		initTouchRect(autoFind);
		if (teamList == null || teamList.size() ==0) {
			return;
		}
		int len = teamList.size();
		int[][] rect = new int[len][];
		for (int i=0;i<len;i++) {
			rect[i] = new int[]{LIST_FRAME_X, LIST_FRAME_Y + LIST_RECT_H * i, LISTNAME_NAME_WIDTH
					+ (LISTNAME_OTHER_WIDTH + LIST_SPACE) * 3, LIST_RECT_H};
		}
		initTouchRect(rect);
	}


	protected void onTouchRect(int[][] rect, int touchid) {
		if (rect == topRect) {
			switch(touchid) {
				case 0://*
					GameTouchManager.keyPressedStar();
					break;
				case 1://#
					GameTouchManager.keyPressedPound();
					break;
				case 2:
//					if (m_teamNear_page != 0) {
//						m_teamNear_page--;
//						teamMemberIndex = m_teamNear_page * m_teamNear_onePageNum;
//					}
					GameTouchManager.keyPressedDir(0);
					break;
				case 3:
					GameTouchManager.keyPressedDir(2);
//					if (m_teamNear_page != m_teamNear_sumPage - 1) {
//						m_teamNear_page++;
//						teamMemberIndex = m_teamNear_page * m_teamNear_onePageNum;
//					}
					break;
			}
		} else if (rect == autoFind) {
			GameTouchManager.keyPressedNum(1);
		} else {//列表
			if (teamMemberIndex == touchid) {
				GameTouchManager.keyPressedFire();	
			} else {
				teamMemberIndex = touchid;
			}
			
		}
	}


	protected void paintContent(Graphics g)
	{
		UITools.clearScreen(g); // 清屏
		// 绘制背景
		UITools.paintBackGround(g, UITools.X_BG, UITools.Y_BG, UITools.W_BG,
				UITools.H_BG, "队伍", true, true);
		switch (m_state) {
			case TEAM_SELF:
				drawTeamSelf(g); // 画自己的队伍
				break;
			case TEAM_NEAR:
				drawTeamNear(g);// 附近队伍
				break;
			default:
				break;
		}
	}

	private boolean flag = false;

	protected void keyLogic()
	{
		m_currframeCount++;
		if (m_state == TEAM_SELF) {
			if (flag) {
				unitRollx();
			}
			logicTeamSelf();
		}
		else if (m_state == TEAM_NEAR) {
			if (flag) {
				unitRollx();
			}
			logicTeamNear();
		}

	}

	private void logicTeamSelf()
	{

		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if (teamList == null) {
				return;
			}
			Tools.debugPrintln("我的队伍>>>>>>>>");
			ActorRole role = GameManager.getInstance().m_role;
			String[] teamItems = null;
			if (leaderID == role.m_gameID) {// 队长
				if (getIndexID(teamList) == role.m_gameID) {
					teamItems = new String[] { "1.查看", "2.解散队伍", "3.离开队伍",
							"0.返回" };
					final UIPopmenu win = (UIPopmenu) UIManager.getInstance()
							.createWindow(UIWindowFactory.WINDOW_POPMENU);
					win.setPopmenus(teamItems);
					win.addListener(new UIListener() {

						public void actionPerformed()
													{
														if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
															seeRole(teamList);
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 解散队伍
															GameManager.getInstance().m_game_message
																	.sendLeaderHandle(m_team_dismissTeam,
																			(long) 0,
																			getIndexName(teamList));
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {// 退出队伍
															Tools.debugPrintln("Send退出队伍");
															GameManager.getInstance().m_game_message
																	.sendQuitTeam();
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {// 返回
															UIManager.getInstance().removeWindow(win);

														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
																|| AbstractGameScreen
																		.haveKeyPressed(AbstractGameScreen.GK_A)) {
															switch (win.getCurrentIndex()) {
																case 0:// 查看
																	seeRole(teamList);
																	break;
																case 1:// 解散队伍
																	GameManager.getInstance().m_game_message
																			.sendLeaderHandle(
																					m_team_dismissTeam,
																					(long) 0,
																					getIndexName(teamList));
																	break;
																case 2:// 离开队伍
																	Tools.debugPrintln("Send退出队伍");
																	GameManager.getInstance().m_game_message
																			.sendQuitTeam();
																	break;
																case 3:// 返回
																	break;
															}
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
																|| AbstractGameScreen
																		.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
															UIManager.getInstance().removeWindow(win);
														}
													}
					});
				}
				else {
					teamItems = new String[] { "1.查看", "2.加为好友", "3.踢出队伍",
							"4.转让队长", "5.解散队伍", "6.传音入密", "7.交易", "8.加入黑名单",
							"0.返回" };
					UIPopmenu win = (UIPopmenu) UIManager.getInstance()
							.createWindow(UIWindowFactory.WINDOW_POPMENU);
					win.setPopmenus(teamItems);
					win.addListener(getListenerCaptianMenu(win));
				}

			}
			else {// 队员
				if (getIndexID(teamList) == role.m_gameID) {
					teamItems = new String[] { "1.查看", "2.退出队伍", "0.返回" };
					final UIPopmenu win = (UIPopmenu) UIManager.getInstance()
							.createWindow(UIWindowFactory.WINDOW_POPMENU);
					win.setPopmenus(teamItems);
					win.addListener(new UIListener() {

						public void actionPerformed()
													{
														if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
															seeRole(teamList);
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {// 退出队伍
															Tools.debugPrintln("Send退出队伍");
															GameManager.getInstance().m_game_message
																	.sendQuitTeam();
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {// 返回
															UIManager.getInstance().removeWindow(win);

														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
																|| AbstractGameScreen
																		.haveKeyPressed(AbstractGameScreen.GK_A)) {
															switch (win.getCurrentIndex()) {
																case 0:// 查看
																	seeRole(teamList);
																	break;
																case 1:// 离开队伍
																	Tools.debugPrintln("Send退出队伍");
																	GameManager.getInstance().m_game_message
																			.sendQuitTeam();
																	break;
																case 2:// 返回
																	break;
															}
															UIManager.getInstance().removeWindow(win);
														}
														else if (AbstractGameScreen
																.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
																|| AbstractGameScreen
																		.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
															UIManager.getInstance().removeWindow(win);
														}
													}
					});
				}
				else {
					teamItems = new String[] { "1.查看", "2.加为好友", "3.传音入密",
							"4.交易", "5.加入黑名单", "0.返回" };
					UIPopmenu win = (UIPopmenu) UIManager.getInstance()
							.createWindow(UIWindowFactory.WINDOW_POPMENU);
					win.setPopmenus(teamItems);
					win.addListener(getListenerPlayerMenu(win));
				}
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (teamList != null) {
				if (teamMemberIndex > 0) {
					teamMemberIndex--;
				}
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (teamList != null) {
				if (teamMemberIndex < teamList.size() - 1) {
					teamMemberIndex++;
				}
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_B)) {
			if (m_state != 1) {
				flag = false;
				GameManager.getInstance().m_game_message.sendTeamNear();
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_D)) {
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
			if (teamID == 0) {
				GameManager.getInstance().m_game_message.sendTeamAutoCreate();
			}
		}

	}

	private void logicTeamNear()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if (nearTeamList == null || nearTeamList.size() == 0) {
				return;
			}
			String[] nearTeamItems = new String[] { "1.查看", "2,加为好友", "3.申请入队",
					"4.传音入密", "5.加入黑名单", "0.返回" };
			UIPopmenu win = (UIPopmenu) UIManager.getInstance().createWindow(
					UIWindowFactory.WINDOW_POPMENU);
			win.setPopmenus(nearTeamItems);
			win.addListener(getListenerNearbyTeam(win));
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (nearTeamList != null) {
				if (teamMemberIndex > m_teamNear_page * m_teamNear_onePageNum) {
					teamMemberIndex--;
				}
				else if (m_teamNear_page != 0) {
					teamMemberIndex--;
					m_teamNear_page--;
				}
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (nearTeamList != null) {
				if (teamMemberIndex < ((m_teamNear_page == (m_teamNear_sumPage - 1) ? nearTeamList
						.size() : (m_teamNear_page + 1) * m_teamNear_onePageNum) - 1)) {
					teamMemberIndex++;
				}
				else if (m_teamNear_page < (m_teamNear_sumPage - 1)) {
					m_teamNear_page++;
					teamMemberIndex++;
				}
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			if (m_teamNear_page != 0) {
				m_teamNear_page--;
				teamMemberIndex = m_teamNear_page * m_teamNear_onePageNum;
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			if (m_teamNear_page != m_teamNear_sumPage - 1) {
				m_teamNear_page++;
				teamMemberIndex = m_teamNear_page * m_teamNear_onePageNum;
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_D)) {
			if (m_state != 0) {
				flag = false;
				GameManager.getInstance().m_game_message.sendTeamAllMsg();
			}
		}
		else if (AbstractGameScreen
				.haveKeyPressed(AbstractGameScreen.GK_B)) {
		}

	}

	private void drawTeamNear(Graphics g)
	{
		g.setClip(TEAM_LABEL_SELF_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H);
		UITools.paintLabelStr(g, TEAM_LABEL_SELF_X, TEAM_LABEL_Y, TEAM_LABEL_W,
				TEAM_LABEL_H, TEAM_LABEL_SELFNAME, false, false);
		g.setClip(TEAM_LABEL_NEAR_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H);
		UITools.paintLabelStr(g, TEAM_LABEL_NEAR_X, TEAM_LABEL_Y, TEAM_LABEL_W,
				TEAM_LABEL_H, TEAM_LABEL_NEARNAME, true, false);
//		UITools.paintLabelArr(g, TEAM_LABEL_SELF_X - 22, TEAM_LABEL_Y, true, true);
//		UITools.paintLabelArr(g, TEAM_LABEL_NEAR_X + TEAM_LABEL_W, TEAM_LABEL_Y, false, false);
		// 绘制队伍列表的标题
		paintTeamListTitle(g, "队长名称", "人数", "等级", "位置");
		// 绘制队伍信息列表
		paintRectNearbyTeamList(g);
		// 绘制翻页
		UITools.paintPage(g, m_x + (m_w >> 1), m_y + m_h - UITools.IW_WIN, m_teamNear_page,
				m_teamNear_sumPage);

	}

	/**
	 * 绘制队伍成员列表
	 * 
	 * @param g
	 */
	private void drawTeamSelf(Graphics g)
	{
		// 绘制队伍列表的标题
		g.setClip(TEAM_LABEL_SELF_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H);
		UITools.paintLabelStr(g, TEAM_LABEL_SELF_X, TEAM_LABEL_Y, TEAM_LABEL_W,
				TEAM_LABEL_H, TEAM_LABEL_SELFNAME, true, false);
		g.setClip(TEAM_LABEL_NEAR_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H);
		UITools.paintLabelStr(g, TEAM_LABEL_NEAR_X, TEAM_LABEL_Y, TEAM_LABEL_W,
				TEAM_LABEL_H, TEAM_LABEL_NEARNAME, false, false);
//		UITools.paintLabelArr(g, TEAM_LABEL_SELF_X - 22, TEAM_LABEL_Y, true, false);
//		UITools.paintLabelArr(g, TEAM_LABEL_NEAR_X + TEAM_LABEL_W, TEAM_LABEL_Y, false, true);
		paintTeamListTitle(g, "玩家姓名", "种族", "等级", "职业");
		// 绘制队员信息列表
		paintRectTeamMemberList(g);
		// 绘制翻页
		UITools.paintPage(g, m_x + (m_w >> 1), m_y + m_h - UITools.IW_WIN, 0, 1);
		if (teamID == 0) {
			g.setClip(m_x + (m_w >> 1)
					- (TEAM_LABEL_ZHIDONGZUDUI_W >> 1), TEAM_LABEL_ZHIDONGZUDUI_Y,
					TEAM_LABEL_ZHIDONGZUDUI_W, TEAM_LABEL_ZHIDONGZUDUI_H);
			UITools.paintLabelStr(g, (m_x + (m_w >> 1)
					- (TEAM_LABEL_ZHIDONGZUDUI_W >> 1)), TEAM_LABEL_ZHIDONGZUDUI_Y,
					TEAM_LABEL_ZHIDONGZUDUI_W, TEAM_LABEL_ZHIDONGZUDUI_H,
					TEAM_LABEL_ZHIDONGZUDUI_NAME, true);
		}
	}

	/**
	 * 附近队伍列表
	 * 
	 * @param g
	 */
	private void paintRectNearbyTeamList(Graphics g)
	{
		drawTeamFreamAndBG(g);
		if (nearTeamList == null || nearTeamList.size() == 0) {
			teamMemberIndex = -1;
			return;
		}
		for (int i = m_teamNear_page * m_teamNear_onePageNum; i < ((m_teamNear_page == (m_teamNear_sumPage - 1) ? nearTeamList
				.size()
				: (m_teamNear_page + 1) * m_teamNear_onePageNum)); i++) {
			ActorRole memberRole = (ActorRole) nearTeamList.elementAt(i);
			if (i == teamMemberIndex) {
				g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
				UITools.drawSelectBox(g, LIST_FRAME_X, LIST_FRAME_Y + LIST_RECT_H * (i % m_teamNear_onePageNum),
						LISTNAME_NAME_WIDTH
								+ (LISTNAME_OTHER_WIDTH + LIST_SPACE) * 3, LIST_RECT_H);
			}
			drawRectNearbyTeamMSGItem_H(g, UIManager
					.getPaletteColor(UIPalette.COLOR_WORD_NOS), memberRole, i % m_teamNear_onePageNum);
		}
	}

	/**
	 * 绘制队伍列表的标题
	 * 
	 * @param g
	 */
	private void paintTeamListTitle(Graphics g, String str1, String str2,
			String str3, String str4)
	{
		UITools.drawListTitleItem(g, LISTNAME_NAME_X, LISTNAME_NAME_Y,
				LISTNAME_NAME_WIDTH, LISTNAME_HEIGHT, str1);
		UITools.drawListTitleItem(g, LISTNAME_NAME_X + LISTNAME_NAME_WIDTH
				+ LIST_SPACE, LISTNAME_NAME_Y, LISTNAME_OTHER_WIDTH,
				LISTNAME_HEIGHT, str2);
		UITools.drawListTitleItem(g, LISTNAME_NAME_X + LISTNAME_NAME_WIDTH
				+ LIST_SPACE * 2 + LISTNAME_OTHER_WIDTH, LISTNAME_NAME_Y,
				LISTNAME_OTHER_WIDTH, LISTNAME_HEIGHT, str3);
		UITools.drawListTitleItem(g, LISTNAME_NAME_X + LISTNAME_NAME_WIDTH
				+ LIST_SPACE * 3 + LISTNAME_OTHER_WIDTH * 2, LISTNAME_NAME_Y,
				LISTNAME_OTHER_WIDTH, LISTNAME_HEIGHT, str4);

	}

	public static int teamMemberIndex = 0;

	/**
	 * 绘制队员列表
	 * 
	 * @param g
	 */
	private void paintRectTeamMemberList(Graphics g)
	{
		drawTeamFreamAndBG(g);
		if (teamList == null || teamList.size() == 0) {
			teamMemberIndex = -1;
			return;
		}
		synchronized (teamList) {
			for (int i = 0; i < teamList.size(); i++) {
				ActorRole memberRole = (ActorRole) teamList.elementAt(i);
				if (i == teamMemberIndex) {
					g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
					UITools.drawSelectBox(g, LIST_FRAME_X, LIST_FRAME_Y + LIST_RECT_H * i, LISTNAME_NAME_WIDTH
							+ (LISTNAME_OTHER_WIDTH + LIST_SPACE) * 3, LIST_RECT_H);
				}
				drawRectTeamMSGItem_H(g, UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS), memberRole, i);
			}
		}
	}

	private void drawTeamFreamAndBG(Graphics g)
	{
		drawRectTeamListBG(g, LIST_FRAME_X, LIST_FRAME_Y, LISTNAME_NAME_WIDTH,
				LIST_HELGHT);
		drawRectTeamListBG(g, LIST_FRAME_X + LISTNAME_NAME_WIDTH + LIST_SPACE,
				LIST_FRAME_Y, LISTNAME_OTHER_WIDTH, LIST_HELGHT);
		drawRectTeamListBG(g, LIST_FRAME_X + LISTNAME_NAME_WIDTH + LIST_SPACE
				* 2 + LISTNAME_OTHER_WIDTH, LIST_FRAME_Y, LISTNAME_OTHER_WIDTH,
				LIST_HELGHT);
		drawRectTeamListBG(g, LIST_FRAME_X + LISTNAME_NAME_WIDTH + LIST_SPACE
				* 3 + LISTNAME_OTHER_WIDTH * 2, LIST_FRAME_Y,
				LISTNAME_OTHER_WIDTH, LIST_HELGHT);
	}

	/**
	 * 绘制队员信息列表 一列
	 * 
	 * @param g
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 * @param data
	 * @param type
	 */
	private void drawRectTeamListBG(Graphics g, int x, int y, int w, int h)
	{
		g.setClip(x, y, w, h - 1);
//		for (int i = 0; i < LIST_HELGHT / LIST_RECT_H + 1; i++) {
//			if (i % 2 == 0) {
//				g.setColor(UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
//				g.fillRect(x + 2, y + 2 + LIST_RECT_H * i, w - 3, LIST_RECT_H);
//			}
//			else {
//				g.setColor(UIManager.getPaletteColor(UIPalette.COLOR_CBD_LIGHT));
//				g.fillRect(x + 2, y + 2 + LIST_RECT_H * i, w - 3, LIST_RECT_H);
//			}
//		}
		UITools.drawListFrame(g, x, y, w, h);
	}

	/***
	 * 绘制队员信息列表数据 行
	 * 
	 * @param g
	 * @param x
	 * 宽中间的X
	 * @param y
	 * @param role
	 */
	private void drawRectTeamMSGItem_H(Graphics g, int colour, ActorRole role,
			int hint)
	{
		g.setClip(LIST_FRAME_X + 2, LIST_FRAME_Y + 2 + LIST_RECT_H * hint,
				LISTNAME_NAME_WIDTH - 4, LIST_RECT_H);
		UITools.drawColorString(g, role.m_name, LIST_FRAME_X - m_unitRollx[hint] + 2
				, LIST_FRAME_Y + LIST_RECT_H * hint + STRING_LIST_Y, colour, Graphics.TOP | Graphics.LEFT);

		g.setClip(LIST_FRAME_X + 2 + LISTNAME_NAME_WIDTH + LIST_SPACE, LIST_FRAME_Y + 2 + LIST_RECT_H * hint,
				(LIST_SPACE + LISTNAME_OTHER_WIDTH) * 3, LIST_RECT_H);
		UITools.drawColorString(g, ActorRole.ROLE_RACE_LIST[role.m_race],
				LIST_FRAME_X + LISTNAME_NAME_WIDTH + LIST_SPACE * 1
						+ (LISTNAME_OTHER_WIDTH >> 1), LIST_FRAME_Y
						+ +LIST_RECT_H * hint + STRING_LIST_Y, colour, Graphics.TOP
						| Graphics.HCENTER);
		if (role.m_online) {
			UITools.drawColorString(g, role.m_grade + "", LIST_FRAME_X
					+ LISTNAME_NAME_WIDTH + LIST_SPACE * 2
					+ (LISTNAME_OTHER_WIDTH >> 1) + LISTNAME_OTHER_WIDTH,
					LIST_FRAME_Y + LIST_RECT_H * hint + STRING_LIST_Y, colour,
					Graphics.TOP | Graphics.HCENTER);
			UITools.drawColorString(g,
					ActorRole.ROLE_VOCATION_LIST[role.m_vocation[role.m_vocation.length - 1]],
					LIST_FRAME_X + LISTNAME_NAME_WIDTH + LIST_SPACE * 3
							+ (LISTNAME_OTHER_WIDTH >> 1)
							+ LISTNAME_OTHER_WIDTH * 2, LIST_FRAME_Y
							+ LIST_RECT_H * hint + STRING_LIST_Y, colour,
					Graphics.TOP | Graphics.HCENTER);
		}
		else {
			UITools.drawColorString(g, "--", LIST_FRAME_X + LISTNAME_NAME_WIDTH
					+ LIST_SPACE * 2 + (LISTNAME_OTHER_WIDTH >> 1)
					+ LISTNAME_OTHER_WIDTH, LIST_FRAME_Y + 5 + +LIST_RECT_H
					* hint + STRING_LIST_Y, colour, Graphics.TOP | Graphics.HCENTER);
			UITools.drawColorString(g, "--", LIST_FRAME_X + LISTNAME_NAME_WIDTH
					+ LIST_SPACE * 3 + (LISTNAME_OTHER_WIDTH >> 1)
					+ LISTNAME_OTHER_WIDTH * 2, LIST_FRAME_Y + 5 + +LIST_RECT_H
					* hint, colour + STRING_LIST_Y, Graphics.TOP | Graphics.HCENTER);
		}
	}

	/***
	 * 绘制队员信息列表数据 行
	 * 
	 * @param g
	 * @param x
	 * 宽中间的X
	 * @param y
	 * @param role
	 */
	private void drawRectNearbyTeamMSGItem_H(Graphics g, int colour,
			ActorRole role, int hint)
	{
		g.setClip(LIST_FRAME_X + 2, LIST_FRAME_Y + 2 + LIST_RECT_H * hint,
				LISTNAME_NAME_WIDTH - 4, LIST_RECT_H);
		UITools.drawColorString(g, role.m_name, LIST_FRAME_X
				+ (LISTNAME_NAME_WIDTH >> 1), LIST_FRAME_Y + LIST_RECT_H
				* hint + STRING_LIST_Y, colour, Graphics.TOP | Graphics.HCENTER);
		g.setClip(LIST_FRAME_X + 2 + LISTNAME_NAME_WIDTH + LIST_SPACE, LIST_FRAME_Y + 2 + LIST_RECT_H * hint,
				(LIST_SPACE + LISTNAME_OTHER_WIDTH) * 3, LIST_RECT_H);
		UITools.drawColorString(g, role.m_teamMemberNum + "/4", LIST_FRAME_X
				+ LISTNAME_NAME_WIDTH + LIST_SPACE * 1
				+ (LISTNAME_OTHER_WIDTH >> 1), LIST_FRAME_Y + +LIST_RECT_H
				* hint + STRING_LIST_Y, colour, Graphics.TOP | Graphics.HCENTER);
		UITools.drawColorString(g, role.m_grade + "", LIST_FRAME_X
				+ LISTNAME_NAME_WIDTH + LIST_SPACE * 2
				+ (LISTNAME_OTHER_WIDTH >> 1) + LISTNAME_OTHER_WIDTH,
				LIST_FRAME_Y + LIST_RECT_H * hint + STRING_LIST_Y, colour, Graphics.TOP
						| Graphics.HCENTER);
		UITools.drawColorString(g, role.m_location, LIST_FRAME_X
				+ LISTNAME_NAME_WIDTH + LIST_SPACE * 3
				+ (LISTNAME_OTHER_WIDTH >> 1) + LISTNAME_OTHER_WIDTH * 2,
				LIST_FRAME_Y + LIST_RECT_H * hint + STRING_LIST_Y, colour, Graphics.TOP
						| Graphics.HCENTER);
	}

	public int m_currframeCount;
	private boolean[] m_unitIsRoll;//单元区域是否需要滚动
	private int[] m_unitRollx;//单元区域的滚动

	private final int ROLL_STARTTIME = 20;//单元开始滚动的固定时间
	private final int ROLL_OVERTIME = 10;//单元滚动结束等待还原的固定时间
	private int m_rollState;//单元当前滚动状态  ：0开始等待 1滚动中 2滚动结束等待中
	private int m_frameCount = 0;//计算单元滚动时间 用帧数计算

	private void unitRollx()
	{
		if (m_unitIsRoll == null || m_unitRollx == null || teamMemberIndex >= m_unitIsRoll.length
				|| teamMemberIndex < 0) {
			return;
		}
		if (m_unitIsRoll[teamMemberIndex]) {//判断滚动处理  条件必须是当前选中的单元需要滚动
			switch (m_rollState) {//当前需要滚动单元的状态
				case 0://开始等待
					if (m_frameCount == 0) {
						//m_frameCount = GameManager.getInstance().m_scene.m_frameCount; 
						m_frameCount = m_currframeCount;
					}
					else if (m_currframeCount - m_frameCount >= ROLL_STARTTIME) {
						m_rollState = 1;
						m_frameCount = 0;
					}
					break;
				case 1://滚动中
					if (m_unitRollx[teamMemberIndex] < LISTNAME_NAME_WIDTH - (UITools.IW_RECT_CONTENT << 1)) {
						m_unitRollx[teamMemberIndex]++;
					}
					else {
						m_rollState = 2;
					}
					break;
				case 2://结束等待
					if (m_frameCount == 0) {
						//m_frameCount = GameManager.getInstance().m_scene.m_frameCount;
						m_frameCount = m_currframeCount;
					}
					else if (m_currframeCount - m_frameCount >= ROLL_OVERTIME) {
						m_rollState = 0;
						m_frameCount = 0;
						m_unitRollx[teamMemberIndex] = 0;
					}
					break;
			}
		}
		//判断如果当前选项离开充值便宜量
		for (int i = 0; i < m_unitRollx.length; i++) {
			if (m_unitRollx[i] != 0 && teamMemberIndex != i) {
				m_unitRollx[i] = 0;
				break;
			}
		}
	}

	private void initImage()
	{
	}

	private ArrayList teamList = null; // 队伍信息
	private long leaderID = -1;
	private long teamID = 0;

	/**
	 * 获取全队的信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamInfo(DataInputStream dis) throws IOException
	{
		GameManager.getInstance().m_game_message.unlockNetwork();
		short status = dis.readShort(); // 0失败 1成功
		String hint = dis.readUTF(); // 提示信息
		if (status == 0) {
			GameManager.getInstance().addSystemInfo(
					GameManager.SYSTEM_INFO_TYPE_C, hint);
		}
		UITeamWindow window = (UITeamWindow) UIManager.getInstance()
				.getWindowById(UIWindowFactory.WINDOW_ID_TEAM);
		if (window == null) {
			window = (UITeamWindow) UIManager.getInstance()
					.createWindow(UIWindowFactory.WINDOW_ID_TEAM);
		}
		window.m_state = 0;
		window.teamID = dis.readLong(); // 队伍的ＩＤ
		if (window.teamID == 0) { // 队伍ＩＤ为０读到此处
			window.teamList = null;
			return;
		}
		window.leaderID = dis.readLong(); // 队长的ＩＤ
		Tools.debugPrintln("组队 队长的ＩＤ" + window.leaderID);
		Tools.debugPrintln("队伍的ＩＤ" + window.teamID);

		window.teamList = new ArrayList();
		window.teamList.removeAllElements();

		window.m_unitIsRoll = null;
		window.m_unitRollx = null;
		int Numplayer = dis.readInt(); // 队员的数量
		Tools.debugPrintln("组队 队员的数量" + Numplayer);

		window.m_unitIsRoll = new boolean[Numplayer];//是否需要滚动
		window.m_unitRollx = new int[Numplayer];//滚动偏移量
		for (int i = 0; i < Numplayer; i++) {
			long id = dis.readLong();

			// ActorRole m_role = (ActorRole)
			// m_scene.getActorById(AbstractGameActor.ACTOR_TYPE_ROLE,
			// id);
			ActorRole teamrole = new ActorRole();

			// if (m_role == null) {
			teamrole.m_gameID = id;
			Tools.debugPrintln("id = " + teamrole.m_gameID);
			teamrole.m_online = dis.readByte() == 0 ? true : false;// 是否在线 0在线//
			// 1不在线

			teamrole.m_name = dis.readUTF();
			teamrole.m_grade = dis.readInt();
			teamrole.m_race = dis.readByte(); // 种族
			short size = dis.readShort();
			teamrole.m_vocation = new byte[size];
			for (short j = 0; j < size; j++) {
				teamrole.m_vocation[j] = dis.readByte();
			}
			window.teamList.addElement(teamrole);
			Tools.debugPrintln("name = " + teamrole.m_name);
			Tools.debugPrintln("grade = " + teamrole.m_grade);
			Tools.debugPrintln("m_race = " + teamrole.m_race);
			// }

			//如果当前目标名字的长度大于显示框体设置需要滚动
			if (AbstractGameScreen.s_font.stringWidth(teamrole.m_name) > (window.LISTNAME_NAME_WIDTH - (UITools.IW_RECT_CONTENT << 1))) {
				window.m_unitIsRoll[i] = true;
			}
			else {
				window.m_unitIsRoll[i] = false;
			}
			window.m_unitRollx[i] = 0;//单元的滚动偏移量
		}
		teamMemberIndex = 0;

		window.flag = true;
		window.registerTouch();
	}

	/**
	 * 接受组队请求确认
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamIsAgree(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("组队邀请");
		final byte status = dis.readByte(); // 0：申请加入队伍1：邀请加入队伍
//		String teammsg = dis.readUTF();
//		Tools.debugPrintln("提示信息" + teammsg);
		String name = dis.readUTF();
		String teammsg;
		final long targetID = dis.readLong();
		Tools.debugPrintln("目标ID" + targetID);

		final UIMessageBox msg = (UIMessageBox) UIManager.getInstance()
				.createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
		if (status == 0) {
			teammsg = name + "请求加入您的队伍";
			msg.setMessage("入队申请", "同意", "不同意", teammsg);
		}
		else if (status == 1) {
			teammsg = name + "向您发出了组队邀请";
			msg.setMessage("邀请组队", "同意", "不同意", teammsg);
		}
		msg.addListener(new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
										|| AbstractGameScreen
												.haveKeyPressed(AbstractGameScreen.GK_A)) {
									GameManager.getInstance().m_game_message.sendisAgree(
											status, targetID, (byte) 1);
									UIManager.getInstance().removeWindow(msg);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									GameManager.getInstance().m_game_message.sendisAgree(
											status, targetID, (byte) 0);
									UIManager.getInstance().removeWindow(msg);
								}
							}
		});
	}

	/**
	 * 组队是否成功
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamIsSucceed(DataInputStream dis)
			throws IOException
	{
		Tools.debugPrintln("组队>>>>>>>>>>>>>");

		short state = dis.readShort();
		Tools.debugPrintln("状态码 : " + state);
		switch (state) {
			case 0:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您不是该队队长，没有邀请玩家入队权限");
				break;
			case 1:
				break;
			case 2:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您的队伍已满员");
				break;
			case 3:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方已在您的队伍中");
				break;
			case 4:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方正在其他队伍中");
				break;
			case 5:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您在对方的黑名单中");
				break;
			case 6:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您不能邀请自己哦，亲!");
				break;
			case 7:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方正在其他队伍中");
				break;
			case 8:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"无法创建队伍");
				break;
			case 9:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方拒绝了您的组队邀请");
				break;
			case 10:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"传送目标玩家失败");
				break;
			case 11:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"无法获得队伍信息 ");
				break;
			case 12:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方在您的黑名单中");
				break;
			case 13:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对方与您不在同一阵营");
				break;
		}
	}

	/**
	 * 退出队伍是否成功
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamRequst(DataInputStream dis) throws IOException
	{
		short status = dis.readShort(); // 是否成功
//		String msg = dis.readUTF(); // 提示信息
		switch (status) {
			case 0:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您当前不在任何队伍中");
				break;
			case 1:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您已经离开了当前队伍");
				break;
			case 2:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"无法获取队伍信息");
				break;
			case 3:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您不在当前队伍中");
				break;
		}
		Tools.debugPrintln("退出队伍>>>>>>>>>>>>>>");
		if (status == 1) {
			UITeamWindow window = (UITeamWindow) UIManager.getInstance()
					.getWindowById(UIWindowFactory.WINDOW_ID_TEAM);
			if (window == null) {
				window = (UITeamWindow) UIManager.getInstance()
						.createWindow(
								UIWindowFactory.WINDOW_ID_TEAM);
			}
			window.teamList = null;
			window.teamID = 0;
			window.m_unitIsRoll = null;
			window.m_unitRollx = null;
			teamMemberIndex = -1;
			GameManager.getInstance().m_role.m_roleTeam.removeAllElements();
			window.registerTouch();
		}
		
	}

	/**
	 * 队长操作
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamLeader(DataInputStream dis) throws IOException
	{
		short status = dis.readShort(); // 是否成功
//		String msg = dis.readUTF(); // 提示信息

//		GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C, msg);
		Tools.debugPrintln("队长 操作>>>>>>>>>>>>>>");
		switch (status) {
			case 0:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您当前不在任何队伍中");
				break;
			case 1:
				break;
			case 2:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"无法获取队伍信息");
				break;
			case 3:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您不是该队队长，没有该操作权限。");
				break;
			case 4:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您不能对自己执行队长操作");
				break;
			case 5:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"转让对象不在线");
				break;
			case 6:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"对象不在您的队伍中");
				break;
		}
		UITeamWindow window = (UITeamWindow) UIManager.getInstance()
				.getWindowById(UIWindowFactory.WINDOW_ID_TEAM);
		if (window == null) {
			window = (UITeamWindow) UIManager.getInstance()
					.createWindow(
							UIWindowFactory.WINDOW_ID_TEAM);
		}
		byte type = dis.readByte();// 队长操作类型0:转让队长1.踢出队员2。解散
		long id = dis.readLong(); // 目标ID
		switch (type) {
			case 0:
				if (status == 1) {
					window.leaderID = -1;
				}
				break;
			case 1:
				if (status == 1) {
					int size = window.teamList.size();
					for (int i = 0; i < size; i++) {
						ActorRole role = (ActorRole) window.teamList.elementAt(i);
						if (id == role.m_gameID) {
							window.teamList.removeElementAt(i);
							teamMemberIndex--;
							for (int j = i; j < size; j++) {
								if (j != (size - 1)) {
									window.m_unitIsRoll[j] = window.m_unitIsRoll[j + 1];
									window.m_unitRollx[j] = window.m_unitRollx[j + 1];
								}
							}
							break;
						}
					}
				}
				break;
			case 2:
				if (status == 1) {
					window.teamList = null;
					window.teamID = 0;
					window.leaderID = -1;
					teamMemberIndex = -1;
					window.m_unitIsRoll = null;
					window.m_unitRollx = null;
				}
				break;
			default:
				break;
		}
//		if (type == 1) {
//			UITeamWindow.teamMemberIndex--;
//		}
//		if (type == 2) {
//			if (type == m_team_dismissTeam) {
//				window.teamList = null;
//				window.teamID = 0;
//				window.leaderID = -1;
//			}
//		}
		if (status == 1) {
			window.registerTouch();
		}
	}

	private ArrayList nearTeamList = null;

	/**
	 * 附近队伍
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamNearby(DataInputStream dis) throws IOException
	{
		GameManager.getInstance().m_game_message.unlockNetwork();
		int teamNum = dis.readInt(); // 附近队伍数量
		UITeamWindow teamWin = (UITeamWindow) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_TEAM);
		if (teamWin == null) {
			teamWin = (UITeamWindow) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_TEAM);
		}
		teamWin.m_state = 1;
		if (teamNum == 0 || teamNum < 0) {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "附近暂时没有队伍");
			return;
		}
		teamWin.m_unitIsRoll = null;
		teamWin.m_unitRollx = null;
		Tools.debugPrintln("附近队伍》》》");
		teamWin.m_unitIsRoll = new boolean[teamNum];//是否需要滚动
		teamWin.m_unitRollx = new int[teamNum];//滚动偏移量
		teamWin.nearTeamList = new ArrayList();
		for (int i = 0; i < teamNum; i++) {
			ActorRole nearbyLeader = new ActorRole();
			nearbyLeader.m_teamID = dis.readLong(); // 队伍ID
			nearbyLeader.m_teamMemberNum = dis.readInt();// 队伍人数
			nearbyLeader.m_name = dis.readUTF();// 队长名字
			nearbyLeader.m_location = dis.readUTF();// 队长所在的场景
			nearbyLeader.m_grade = dis.readInt();
			teamWin.nearTeamList.addElement(nearbyLeader);

			//如果当前目标名字的长度大于显示框体设置需要滚动
			if (AbstractGameScreen.s_font.stringWidth(nearbyLeader.m_name) > (teamWin.LISTNAME_NAME_WIDTH - (UITools.IW_RECT_CONTENT << 1))) {
				teamWin.m_unitIsRoll[i] = true;
			}
			else {
				teamWin.m_unitIsRoll[i] = false;
			}
			teamWin.m_unitRollx[i] = 0;//单元的滚动偏移量
		}

		teamWin.m_state = 1;
		if (teamWin.nearTeamList.size() != 0) {
			teamWin.m_teamNear_sumPage = teamWin.nearTeamList.size() / teamWin.m_teamNear_onePageNum + 1;
		}
		teamMemberIndex = 0;

		teamWin.m_teamNear_page = 0;
		teamWin.flag = true;
	}

	/**
	 * 申请入队是否成功
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamApplyJoin(DataInputStream dis)
			throws IOException
	{
		short stats = dis.readShort(); // 状态0 失败1成功
//		String hint = dis.readUTF(); // 提示信息
		switch (stats) {
			case 0:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"无法获取对方队伍信息");
				break;
			case 1:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"申请加入队伍成功");
				break;
			case 2:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"目标队伍已满员");
				break;
			case 3:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您当前已在队伍中，不能同时加入两个队伍");
				break;
			case 4:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"您在该队队长的黑名单中");
				break;
			case 5:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"目标队伍队长不在线");
				break;
			case 6:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
						"目标队伍队长拒绝了您的加入队伍请求");
				break;
		}
	}

	/**
	 * xujianping 自动组队
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTeamAutoCreate(DataInputStream dis)
			throws IOException
	{
		GameManager.getInstance().m_game_message.unlockNetwork();
		short state = dis.readShort(); // 状态 ：0失败1成功
		String msg = dis.readUTF(); // 提示信息
		Tools.debugPrintln("Team Auto Create-->state" + state);
		Tools.debugPrintln("Team Auto Create-->提示信息" + msg);
		GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_C,
				msg);

	}

	byte m_team_changeLeader = 0; // 转让队长
	static byte m_team_outPlayer = 1; // 踢出队员
	static byte m_team_dismissTeam = 2;// 解散队伍

	/**
	 * 队长菜单
	 * 
	 * @param i
	 */
	private UIListener getListenerCaptianMenu(final UIPopmenu win)
	{
		UIListener listener = new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
									seeRole(teamList);
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 加为好友
									GameManager.getInstance().m_game_message.sendSocialAdd(
											(byte) 0, getIndexID(teamList),
											getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {// 踢出队伍
									GameManager.getInstance().m_game_message.sendLeaderHandle(
											m_team_outPlayer, getIndexID(teamList),
											getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {// 转让队长
									GameManager.getInstance().m_game_message.sendLeaderHandle(
											m_team_changeLeader, getIndexID(teamList),
											getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {// 解散队伍
									GameManager.getInstance().m_game_message.sendLeaderHandle(
											m_team_dismissTeam, (long) 0,
											getIndexName(teamList));
									GameManager.getInstance().m_role.m_leaderID = -1;
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY6)) {// 传音入密
									writeMsg(teamList);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY7)) {// 交易
									Deal(teamList);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY8)) {// 加入黑名单
									GameManager.getInstance().m_game_message.sendSocialAdd(
											GameManager.SOCIAL_TYPE_BLACKLIST,
											getIndexID(teamList), getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_A)
										|| AbstractGameScreen
												.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
									switch (win.getCurrentIndex()) {
										case 0:// 查看
											seeRole(teamList);
											break;
										case 1:// 加为好友
											GameManager.getInstance().m_game_message.sendSocialAdd(
													GameManager.SOCIAL_TYPE_FRIEND,
													getIndexID(teamList), getIndexName(teamList));
											break;
										case 2:// 踢出队伍
											GameManager.getInstance().m_game_message
													.sendLeaderHandle(m_team_outPlayer,
															getIndexID(teamList),
															getIndexName(teamList));
											break;
										case 3:// 转让队长
											GameManager.getInstance().m_game_message
													.sendLeaderHandle(m_team_changeLeader,
															getIndexID(teamList),
															getIndexName(teamList));
											break;
										case 4:// 解散队伍
											GameManager.getInstance().m_game_message
													.sendLeaderHandle(m_team_dismissTeam, (long) 0,
															getIndexName(teamList));
											GameManager.getInstance().m_role.m_leaderID = -1;
											break;
										case 5:// 传音入密
											writeMsg(teamList);
											break;
										case 6:// 交易
											Deal(teamList);
											break;
										case 7:// 加入黑名单
											GameManager.getInstance().m_game_message.sendSocialAdd(
													GameManager.SOCIAL_TYPE_BLACKLIST,
													getIndexID(teamList), getIndexName(teamList));
											break;
										case 8:// 返回
											UIManager.getInstance().removeWindow(win);
											break;
									}
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
										|| AbstractGameScreen
												.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
									UIManager.getInstance().removeWindow(win);
								}
							}
		};
		return listener;
	}

	/**
	 * 队员菜单
	 * 
	 * @param element
	 * 
	 * @param element
	 */
	private UIListener getListenerPlayerMenu(final UIPopmenu win)
	{
		UIListener listener = new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
									seeRole(teamList);
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 加为好友
									GameManager.getInstance().m_game_message.sendSocialAdd(
											(byte) 0, getIndexID(teamList),
											getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {// 传音入密
									writeMsg(teamList);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {// 加入黑名单
									GameManager.getInstance().m_game_message.sendSocialAdd(
											GameManager.SOCIAL_TYPE_BLACKLIST,
											getIndexID(teamList), getIndexName(teamList));
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
										|| AbstractGameScreen
												.haveKeyPressed(AbstractGameScreen.GK_A)) {
									switch (win.getCurrentIndex()) {
										case 0:// 查看
											seeRole(teamList);
											break;
										case 1:// 加为好友
											GameManager.getInstance().m_game_message.sendSocialAdd(
													(byte) 0, getIndexID(teamList),
													getIndexName(teamList));
											break;
										case 2:// 传音入密
											writeMsg(teamList);
											break;
										case 3:// 交易
											Deal(teamList);
											break;
										case 4:// 加入黑名单
											GameManager.getInstance().m_game_message.sendSocialAdd(
													GameManager.SOCIAL_TYPE_BLACKLIST,
													getIndexID(teamList), getIndexName(teamList));
											break;
										case 5:// 返回
											break;
									}
									UIManager.getInstance().removeWindow(win);
								}
								else if (AbstractGameScreen
										.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
										|| AbstractGameScreen
												.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
									UIManager.getInstance().removeWindow(win);
								}
							}
		};

		return listener;
	}

	/**
	 * 附近队伍监听
	 * 
	 * @param win
	 * @return
	 */
	private UIListener getListenerNearbyTeam(final UIPopmenu win)
	{
		return new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
					seeRole(nearTeamList);
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 加为好友
					GameManager.getInstance().m_game_message
							.sendSocialAddForName(
									GameManager.SOCIAL_TYPE_FRIEND,
									getIndexName(nearTeamList));
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {// 申请入队
					ActorRole role = null;
					for (int i = 0; i < nearTeamList.size(); i++) {
						role = (ActorRole) nearTeamList
								.elementAt(teamMemberIndex);
					}
					GameManager.getInstance().m_game_message.sendTeamJoin(role.m_teamID);
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {// 密语
					writeMsg(nearTeamList);
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {// 加黑名单
					GameManager.getInstance().m_game_message
							.sendSocialAddForName(
									GameManager.SOCIAL_TYPE_BLACKLIST,
									getIndexName(nearTeamList));
					UIManager.getInstance().removeWindow(win);

				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen
								.haveKeyPressed(AbstractGameScreen.GK_A)) {
					switch (win.getCurrentIndex()) {
						case 0:// 查看
							seeRole(nearTeamList);
							break;
						case 1:// 加为好友
							GameManager.getInstance().m_game_message
									.sendSocialAddForName(
											GameManager.SOCIAL_TYPE_FRIEND,
											getIndexName(nearTeamList));
							break;
						case 2:// 申請入隊
							ActorRole role = null;
							for (int i = 0; i < nearTeamList.size(); i++) {
								role = (ActorRole) nearTeamList
										.elementAt(teamMemberIndex);
							}
							GameManager.getInstance().m_game_message
									.sendTeamJoin(role.m_teamID);
							break;
						case 3:// 密語
							writeMsg(nearTeamList);
							break;
						case 4:// 加入黑名单
							GameManager.getInstance().m_game_message
									.sendSocialAddForName(
											GameManager.SOCIAL_TYPE_BLACKLIST,
											getIndexName(nearTeamList));
							break;
						case 6:// 返回
							break;
					}
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
						|| AbstractGameScreen
								.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
					UIManager.getInstance().removeWindow(win);
				}
			}
		};
	}

	/**
	 * 根据列表的数据的下标 找到对应人物的ID
	 * 
	 * @return role.m_gameID
	 */
	private long getIndexID(ArrayList list)
	{
		if (teamMemberIndex < 0) {
			return 0;
		}
		ActorRole role = new ActorRole();
		ArrayList roleList = list;
		role = (ActorRole) roleList.elementAt(teamMemberIndex);
		return role.m_gameID;
	}

	/**
	 * 根据列表的数据的下标 找到对应人物的name
	 * 
	 * @return role.m_gameID
	 */
	private String getIndexName(ArrayList list)
	{
		if (teamMemberIndex < 0) {
			return "";
		}
		ActorRole role = new ActorRole();
		ArrayList roleList = list;
		role = (ActorRole) roleList.elementAt(teamMemberIndex);
		return role.m_name;
	}

	/**
	 * 查看玩家属性
	 */
	private void seeRole(ArrayList list)
	{
		GameManager.getInstance().m_game_message.sendAttInfos(getIndexID(list));
	}

	/**
	 * 写信
	 */
	private void writeMail(ArrayList list)
	{
		UIMail.sendMailToPlayer(getIndexName(list));
	}

	/**
	 * 私聊
	 */
	private void writeMsg(ArrayList list)
	{
		UIChatInsert.gotoSiliao(getIndexID(list), getIndexName(list));
	}

	/**
	 * 交易
	 */
	private void Deal(ArrayList list)
	{
		GameManager.getInstance().m_game_message.sendDealRequest(getIndexID(list));
	}

	protected void close()
	{
		super.close();
		if (nearTeamList != null) {
			nearTeamList = null;
		}
		if (teamList != null) {
			teamList = null;
		}
	}

	// ////////////////通用信息/////////////////////
	private int TEAM_LABEL_W = 80;
	private int TEAM_LABEL_H = 22;
	private int TEAM_LABEL_Y = UITools.Y_BG + UITools.INITY_CONTENT; // 标签y点坐标
	private int TEAM_LABEL_SELF_X = UITools.X_BG + (UITools.W_BG >> 1) - TEAM_LABEL_W;
	private String TEAM_LABEL_SELFNAME = "我的队伍";
	private int TEAM_LABEL_NEAR_X = UITools.X_BG + (UITools.W_BG >> 1);
	private String TEAM_LABEL_NEARNAME = "附近队伍";

	private final int LISTNAME_HEIGHT = 23;// 所有标题H
	//#if screen == "640360"
	 private final int LISTNAME_NAME_WIDTH = 120; // 玩家姓名标题w和列表
	//#else
//	private final int LISTNAME_NAME_WIDTH = 82; // 玩家姓名标题w和列表
	//#endif
	private final int LISTNAME_OTHER_WIDTH = 36; // 其它标题W和列表
	private final int LIST_RECT_H = 22; // 列表高 ，通用 、内
	private final int LIST_SPACE = 2; // 标题自间的间隔

	private final int LISTNAME_NAME_X = UITools.X_BG
			+ ((UITools.W_BG - LISTNAME_NAME_WIDTH - LISTNAME_OTHER_WIDTH * 3 - LIST_SPACE * 3) >> 1); // 玩家名字标题X
	private final int LISTNAME_NAME_Y = TEAM_LABEL_Y + TEAM_LABEL_H + UITools.IH_RECTS; // 玩家名字标题Ｙ
	private final int LIST_HELGHT = UITools.H_RECT - UITools.H_LABEL
			- (LIST_SPACE + LISTNAME_HEIGHT) - (UITools.H_LABEL - UITools.H_SOFTKEY);// 所有列表的高

	private final int LIST_FRAME_X = UITools.X_BG
			+ ((UITools.W_BG - LISTNAME_NAME_WIDTH - LISTNAME_OTHER_WIDTH * 3 - LIST_SPACE * 3) >> 1); // 玩家姓名列表x
	private final int LIST_FRAME_Y = LISTNAME_NAME_Y + LISTNAME_HEIGHT + LIST_SPACE;// 玩家姓名列表Y

	private int TEAM_LABEL_ZHIDONGZUDUI_Y = LIST_FRAME_Y + LISTNAME_HEIGHT * 5;
	private int TEAM_LABEL_ZHIDONGZUDUI_W = 80;
	private int TEAM_LABEL_ZHIDONGZUDUI_H = 22;
	private String TEAM_LABEL_ZHIDONGZUDUI_NAME = "1.自动组队";

	private final int STRING_LIST_Y = (LIST_RECT_H - AbstractGameScreen.FONT_H) >> 1; //文字顶部距离

	private int m_teamNear_page = 0;
	private int m_teamNear_sumPage = 1;
	private int m_teamNear_onePageNum = (LIST_HELGHT - UITools.IW_WIN) / LIST_RECT_H;
	
	int topRect[][] = new int[][]{
			{TEAM_LABEL_SELF_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H},//*
			{TEAM_LABEL_NEAR_X, TEAM_LABEL_Y, TEAM_LABEL_W, TEAM_LABEL_H},//#
			{185,269,43,24},
			{251,269,43,24},
			
	};
	
	int autoFind[][] = new int[][]{
			{(AbstractGameScreen.SCREEN_WIDTH -TEAM_LABEL_ZHIDONGZUDUI_W) >> 1, TEAM_LABEL_ZHIDONGZUDUI_Y,
				TEAM_LABEL_ZHIDONGZUDUI_W, TEAM_LABEL_ZHIDONGZUDUI_H}
	};
}
